<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: LV
  Date: 2016/7/16
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%--<meta charset="UTF-8">--%>
    <%--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">--%>
    <%--<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />--%>
    <%--<!-- 全屏 -->--%>
    <%--<meta name="apple-mobile-web-app-capable" content="yes" />--%>
    <%--<!-- 上方栏显示 -->--%>
    <%--<meta name="apple-mobile-web-app-status-bar-style" content="black" />--%>
    <%--<!-- 不自动识别号码 -->--%>
    <%--<meta name="format-detection" content="telephone=no">--%>
    <%--<link href="${ctx}/assets/public_skin/css/reset.css" rel="stylesheet">--%>
    <%--<link href="${ctx}/assets/public_skin/css/shop_style.css" rel="stylesheet">--%>
    <%--<script src="${ctx}/assets/public_skin/js/jquery-1.11.1.min.js" type="text/javascript"></script>--%>
    <%--<script src="${ctx}/assets/public_skin/js/shop.common.js" type="text/javascript"></script>--%>
    <title>编辑收货地址</title>
    <script type="text/javascript">
        $(function ($) {
            $("#select1").children("option").remove();
            $("#select2").children("option").remove();
            $("#select3").children("option").remove();
            $("#select1").append("<option value=''>"+"--请选择省、直辖市--"+"</option>");
            $("#select2").append("<option value=''>"+"--请选择市、省直辖市--"+"</option>");
            $("#select3").append("<option value=''>"+"--请选择县、区--"+"</option>");
            $.getJSON("${ctx}/shopping/getAreasByParentCode?pcid=no", function(json){
                //alert("JSON Data: " +json);
                //alert(json.length);
                if(json.areaList!=null&&json.areaList!=undefined) {
                    var pcode=($("#provinceCode").val());
                    for (var i in json.areaList) {
                        //alert(json[i].areaName);
                        if(pcode!=null&&pcode!=''&&pcode!=undefined) {
                            if (pcode == json.areaList[i].areaCode) {
                                $("#select1").append("<option value='" + json.areaList[i].areaCode + "' selected='selected'>" + json.areaList[i].areaName + "</option>");

                                $("#select2").children("option").remove();
                                $("#select3").children("option").remove();
                                $("#select2").append("<option value=''>"+"--请选择市、省直辖市--"+"</option>");
                                $("#select3").append("<option value=''>"+"--请选择县、区--"+"</option>");
                                var selectTmp=$("#select1").val();

                                if(selectTmp!=''){
                                    $.getJSON("${ctx}/shopping/getAreasByParentCode?pcid="+selectTmp, function(json){
                                        //alert("JSON Data: " +json);
                                        var ccode=$("#cityCode").val();
                                        if(json.areaList!=null&&json.areaList!=undefined) {
                                            for (var i in json.areaList) {
                                                //alert(json[i].areaName);
                                                if(ccode!=null&&ccode!=''&&ccode!=undefined){
                                                    if(ccode==json.areaList[i].areaCode){
                                                        $("#select2").append("<option value='" + json.areaList[i].areaCode + "' selected='selected'>" + json.areaList[i].areaName + "</option>");

                                                        $("#select3").children("option").remove();
                                                        $("#select3").append("<option value=''>"+"--请选择县、区--"+"</option>");
                                                        var selectTmp=$("#select2").val();
                                                        //给隐藏市名添加值
                                                        if(selectTmp!=''){
                                                            $.getJSON("${ctx}/shopping/getAreasByParentCode?pcid="+selectTmp, function(json){
                                                                if(json.areaList!=null&&json.areaList!=undefined) {
                                                                    var dcode=$("#districtCode").val();
                                                                    for (var i in json.areaList) {
                                                                        //alert(json[i].areaName);
                                                                        if(dcode!=null&&dcode!=''&&dcode!=undefined){
                                                                            if(dcode==json.areaList[i].areaCode)
                                                                                $("#select3").append("<option value='" + json.areaList[i].areaCode + "' selected='selected'>" + json.areaList[i].areaName + "</option>");
                                                                            else
                                                                                $("#select3").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                                                                        }else
                                                                            $("#select3").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                                                                    }
                                                                }else {
                                                                    alert("出错了");
                                                                    window.location.href="${ctx}/error";
                                                                }
                                                                if(json.url!=null&&json.url!=undefined) window.location.href="${ctx}/"+json.url;
                                                            });
                                                        }
                                                    }else
                                                        $("#select2").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                                                }else
                                                    $("#select2").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                                            }
                                        }else {
                                            alert("出错了");
                                            window.location.href="${ctx}/error";
                                        }
                                        if(json.url!=null&&json.url!=undefined) window.location.href="${ctx}/"+json.url;
                                    });
                                }
                            }
                            else
                                $("#select1").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                        }else{
                            $("#select1").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                        }
                    }
                }else {
                    alert("出错了");
                    window.location.href="${ctx}/error";
                }
                if(json.url!=null&&json.url!=undefined) window.location.href="${ctx}/"+json.url;
            });

            //省市发生改变时
            $("#select1").change(function () {
                $("#select2").children("option").remove();
                $("#select3").children("option").remove();
                $("#select2").append("<option value=''>"+"--请选择市、省直辖市--"+"</option>");
                $("#select3").append("<option value=''>"+"--请选择县、区--"+"</option>");
                var selectTmp=$("#select1").val();
                //给隐藏省名添加值
                $("#provinceName").val($("#select1 option:selected").text());
                if(selectTmp!=''){
                    $.getJSON("${ctx}/shopping/getAreasByParentCode?pcid="+selectTmp, function(json){
                        //alert("JSON Data: " +json);
                        if(json.areaList!=null&&json.areaList!=undefined) {
                            for (var i in json.areaList) {
                                //alert(json[i].areaName);
                                $("#select2").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                            }
                        }else {
                            alert("出错了");
                            window.location.href="${ctx}/error";
                        }
                        if(json.url!=null&&json.url!=undefined) window.location.href="${ctx}/"+json.url;
                    });
                }
            })

            //市区发生改变时
            $("#select2").change(function () {
                $("#select3").children("option").remove();
                $("#select3").append("<option value=''>"+"--请选择县、区--"+"</option>");
                var selectTmp=$("#select2").val();
                //给隐藏市名添加值
                $("#cityName").val($("#select2 option:selected").text());
                if(selectTmp!=''){
                    $.getJSON("${ctx}/shopping/getAreasByParentCode?pcid="+selectTmp, function(json){
                        if(json.areaList!=null&&json.areaList!=undefined) {
                            for (var i in json.areaList) {
                                //alert(json[i].areaName);
                                $("#select3").append("<option value='" + json.areaList[i].areaCode + "'>" + json.areaList[i].areaName + "</option>");
                            }
                        }else {
                            alert("出错了");
                            window.location.href="${ctx}/error";
                        }
                        if(json.url!=null&&json.url!=undefined) window.location.href="${ctx}/"+json.url;
                    });
                }
            })

            //区县发生改变时
            $("#select3").change(function () {
                //给隐藏区县名添加值
                $("#districtName").val($("#select3 option:selected").text());
            })


            //提交表单
            $("#submit_form").click(function () {
                $("#address_form").submit();
            })

        })

    </script>
</head>
<body>
<%--<header>--%>
<%--<h1>编辑收货地址</h1>--%>
<%--<a href="javascript:;"></a>--%>
<%--</header>--%>
<form  id="address_form" action="${ctx}/shopping/savingEditShippingAddressCart" method="post">
    <input type="hidden" name="addressId" value="${shippingAddress.addressId}"/>
    <input type="hidden" name="cartIdString" value="${cartIdString}"/>
    <article class="viewports">
        <ul class="list_item2 c3">
            <li class="odr2_b plr20">
                <input class="i_text" type="text" value="${shippingAddress.consigneeName}" name="name"/>
            </li>
            <li class="odr2_b plr20">
                <input class="i_text" type="text" value="${shippingAddress.consigneePhone}" name="phone"/>
            </li>
            <%--<li class="odr2_b plr20">--%>
            <%--<input class="i_text" type="text" value="10000">--%>
            <%--</li>--%>
            <%--<li class="odr2_b plr20">--%>
            <%--<span class="c0">北京市东城区</span>--%>
            <%--<span class="r">--%>
            <%--<i class="ico-30 ico_arrow"></i>--%>
            <%--</span>--%>
            <%--</li>--%>
            <li class="odr2_b plr20">
                <input type="hidden"  id="provinceCode" value="${shippingAddress.provinceCode}"/>
                <input type="hidden" name="provinceName" id="provinceName" value="${shippingAddress.provinceName}"/>
                <select id="select1" name="provinceCode">
                    <option value="">省</option>
                </select>
            </li>
            <li class="odr2_b plr20">
                <input type="hidden" id="cityCode" value="${shippingAddress.cityCode}"/>
                <input type="hidden" name="cityName" id="cityName" value="${shippingAddress.cityName}"/>
                <select id="select2" name="cityCode">
                    <option value="">市</option>
                </select>
            </li>
            <li class="odr2_b plr20">
                <input type="hidden" id="districtCode" value="${shippingAddress.districtCode}"/>
                <input type="hidden" name="districtName" id="districtName" value="${shippingAddress.districtName}"/>
                <select id="select3" name="districtCode">
                    <option value="">区</option>
                </select>
            </li>
            <li class="odr2_b plr20">
                <textarea class="i_textarea" name="address">${shippingAddress.address}</textarea>
            </li>
        </ul>
        <div class="c p20">
            <c:if test="${shippingAddress.isDefault==1}">
                <div><label class="fwb c0"><input type="checkbox" class="mr10" name="isDefault" checked="checked">设为默认地址</label></div>
            </c:if>
            <c:if test="${shippingAddress.isDefault==0}">
                <div><label class="fwb c0"><input type="checkbox" class="mr10" name="isDefault">设为默认地址</label></div>
            </c:if>
            <div>注：每次下单使用该地址</div>
        </div>
    </article>
</form>
<!--star 底下按钮-->
<div class="buy_height"></div>
<div class="p_fotbtn tac">
    <a class="b-ffaa3b cf ptb25" id="submit_form">保存并使用</a>
    <a class="b-ef2d2d cf ptb25" href="${ctx}/shopping/deleteShippingAddressCart?aid=${shippingAddress.addressId}&cs=${cartIdString}">删除收货地址</a>
</div>
<!--end 底下按钮-->
</body>
</html>
